package com.linkage.jz.bankruptcy.fragment.Vote;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
import com.github.jdsjlzx.recyclerview.ProgressStyle;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Project.ZQUser.DetailOper.ChangerLegalRepActivity;
import com.linkage.jz.bankruptcy.activity.Project.ZQUser.ZQUserDetailActivity;
import com.linkage.jz.bankruptcy.activity.Vote.ProVoteChangeResultActivity;
import com.linkage.jz.bankruptcy.bean.Vote.ProVote;
import com.linkage.jz.bankruptcy.bean.Vote.ProVoteDetail;
import com.linkage.jz.bankruptcy.bean.Vote.VoterDetail;
import com.linkage.jz.bankruptcy.bean.Vote.VoterGroup;
import com.linkage.jz.bankruptcy.bean.ZQUserDetailBaseInfo;
import com.linkage.jz.bankruptcy.event.RefreshEvent;
import com.linkage.jz.bankruptcy.fragment.BaseFragment;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.jz.bankruptcy.widget.datepicker.DateFormatUtils;
import com.linkage.seapeak.activity.message.ScreenUserActivity;
import com.linkage.seapeak.activity.message.ScreenUserShowVoteActivity;
import com.linkage.seapeak.activity.vote.CreditorMultiSelectActivity;
import com.linkage.seapeak.utils.CommonUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import jp.wasabeef.glide.transformations.CropCircleTransformation;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @author AFAP
 * 表决人详情Tab
 */
@SuppressLint("SetTextI18n")
public class ProVoteVotersDetailFragment_Manager extends BaseFragment {

    public static final int STATUS_YBJ = 1; // 1-已表决 2-已参会未表决 3-未参会
    public static final int STATUS_YCHWBJ = 2;
    public static final int STATUS_WCH = 3;

    public static final String ARG_PARAM_VOTE = "ARG_PARAM_VOTE";
    public static final String ARG_PARAM_STATUS = "ARG_PARAM_STATUS";

    private ProVoteDetail mProVoteDetail;
    private int mStatus = 1;

    private TextView screen_member;

    Integer committee = null;
    Boolean onlineStatus = null;
    Boolean kindTax = null;
    Boolean kindGuarantee = null;
    Boolean kindOther = null;
    Boolean kindOrdinary = null;

    Boolean groupkindGuarantee = null;
    Boolean groupkindOther = null;
    Boolean groupkindOrdinary = null;

    Double minAmountDeclared = null;
    Double maxAmountDeclared = null;
    Double minConfirmAmount = null;
    Double maxConfirmAmount = null;
    String processStatus = null;


    private LRecyclerViewAdapter mGroupAdapter;
    private List<VoterGroup> mGroupData = new ArrayList<>();
    private List<Object> mData = new ArrayList<>();
    private TextView tv_voters_overview;
    private SwipeRefreshLayout swipe;

    public static ProVoteVotersDetailFragment_Manager newInstance(ProVoteDetail proVote, int status) {
        ProVoteVotersDetailFragment_Manager fragment = new ProVoteVotersDetailFragment_Manager();
        Bundle args = new Bundle();
        args.putSerializable(ARG_PARAM_VOTE, proVote);
        args.putInt(ARG_PARAM_STATUS, status);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        mProVoteDetail = (ProVoteDetail) getArguments().getSerializable(ARG_PARAM_VOTE);
        mStatus = getArguments().getInt(ARG_PARAM_STATUS, 1);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_pro_vote_voters_details_manager, container, false);
        tv_voters_overview = rootView.findViewById(R.id.tv_voters_overview);
        screen_member = rootView.findViewById(R.id.screen_member);
        LRecyclerView mRecyclerView = rootView.findViewById(R.id.lRecyclerView);
        ProVoteVotersDetailAdapter mDataGroupAdapter = new ProVoteVotersDetailAdapter(getActivity(), mData,
                mRecyclerView);
        mGroupAdapter = new LRecyclerViewAdapter(mDataGroupAdapter);

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setRefreshProgressStyle(ProgressStyle.LineSpinFadeLoader); //设置下拉刷新Progress的样式
        mRecyclerView.setArrowImageView(com.github.jdsjlzx.R.drawable.progressbar);  //设置下拉刷新箭头
        mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallSpinFadeLoader);
        mRecyclerView.setAdapter(mGroupAdapter);
        mRecyclerView.setPullRefreshEnabled(false);
        mRecyclerView.setLoadMoreEnabled(false);
        mRecyclerView.setOnRefreshListener(() -> fetchData());
//        mRecyclerView.forceToRefresh();
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (mStatus == STATUS_WCH) {
            getView().findViewById(R.id.tips).setVisibility(View.VISIBLE);
        }
        swipe = getView().findViewById(R.id.swipe);
        swipe.setColorSchemeColors(0xff25b6ed, 0xff6dbcdb, 0xfff0b650, 0xffff534e, 0xffbed73d, 0xff04bfbf,
                0xffff530d, 0xff61bc46);
        swipe.setEnabled(true);
        swipe.setOnRefreshListener(() -> fetchData());
        fetchData();
        screen_member.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), ScreenUserShowVoteActivity.class);
            intent.putExtra("seltype", "1");
            startActivityForResult(intent, 0x11);
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(RefreshEvent event) {
        if (TextUtils.equals(event.getType(), RefreshEvent.TYPE_VOTER_DETAILS)) {
            fetchData();
        }
    }

    private void fetchData() {
        if (mProVoteDetail.getGroups() != null) {
            getVoterGroup();
        } else {
            VoterGroup group = new VoterGroup();
            mGroupData.clear();
            mGroupData.add(group);
            group.setId("");
            group.setReal(false);
            group.setCurrentPage(0);
            group.setExpand(true);
            getVotersWithGroupId("");
        }
    }

    // 对数据进行预处理
    private void preProcessData() {
        int index = 0;
        mData.clear();
        for (VoterGroup group : mGroupData) {
//           if(!mData.contains(group)){
            if (group.isReal()) {
                mData.add(group);
            }

//           }
            if (group.isExpand()) {
                boolean canLoadMore = group.getMemberDetailList().size() < group.getMemberCount();
                for (int i = 0; i < group.getMemberDetailList().size(); i++) {
                    VoterDetail detail = group.getMemberDetailList().get(i);
                    detail.setGroupId(group.getId());
                    detail.setCanLoadMore(canLoadMore);
                    detail.setLastOne(i == group.getMemberDetailList().size() - 1);
                    mData.add(detail);
                }
            }
        }
    }

    private VoterGroup getGroupById(String id) {
        for (VoterGroup group : mGroupData) {
            if (TextUtils.equals(group.getId(), id)) {
                return group;
            }
        }
        return null;
    }


    private void getVoterGroup() {
//        noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (v.getId() == R.id.btn_save_notice) {
        Network
                .getAPIService()
                .getVotesGroup_Manager(getUserToken(), mProVoteDetail.getId(), mStatus,
                        mProVoteDetail.isDefaultAgreed(), 1, 500)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }
                        JsonObject data = json.getAsJsonObject("data");
                        JsonArray arr = data.getAsJsonArray("list");
                        mGroupData.clear();
                        mGroupData.addAll(VoterGroup.parse(arr));
                        preProcessData();
                        mGroupAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onCompleted() {
                        hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        hideLoading();
                    }
                });
//                }
//                noticeDialog.dismiss();
//            }
//        }, 1, "提示", "请确认操作已获得有效授权",
//                "否", "是");
//        noticeDialog.show();
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0x11 && resultCode == Activity.RESULT_OK && data != null) {
            committee = data.getIntExtra("committee", 1);
            int online = data.getIntExtra("onlineStatus", 0);
            if (online == 0)
                onlineStatus = null;
            else if (online == 1)
                onlineStatus = true;
            else
                onlineStatus = false;
            kindTax = data.getBooleanExtra("kindTax", false);
            kindGuarantee = data.getBooleanExtra("kindGuarantee", false);
            kindOther = data.getBooleanExtra("kindOther", false);
            kindOrdinary = data.getBooleanExtra("kindOrdinary", false);
            minAmountDeclared = data.getDoubleExtra("minAmountDeclared", 0);
            maxAmountDeclared = data.getDoubleExtra("maxAmountDeclared", 0);
            minConfirmAmount = data.getDoubleExtra("minConfirmAmount", 0);
            maxConfirmAmount = data.getDoubleExtra("maxConfirmAmount", 0);
            processStatus = data.getStringExtra("processStatus");
            fetchData();
        }
    }

    private void getVotersWithGroupId(String groupId) {

        LinkedHashMap<String, String> parms = new LinkedHashMap<>();

        VoterGroup group = getGroupById(groupId);
        int tarPage = group.getCurrentPage() + 1;

        parms.put("userToken", getUserToken());
        parms.put("voteId", mProVoteDetail.getId());
        parms.put("projectId", mProVoteDetail.getBankruptcyProjectId());
        parms.put("groupId",   group.getId());
        parms.put("status",   mStatus + "");
        parms.put("defaultAgreed",   mProVoteDetail.isDefaultAgreed() + "");
        parms.put("pageNumber", tarPage + "");
        parms.put("pageSize", 500 + "");

        if (committee != null) parms.put("role", committee + "");
        if (onlineStatus != null) parms.put("onlineStatus", onlineStatus + "");

        if (kindTax != null) parms.put("kindTax", kindTax + "");
        if (kindGuarantee != null) parms.put("kindGuarantee", kindGuarantee + "");
        if (kindOther != null) parms.put("kindOther", kindOther + "");
        if (kindOrdinary != null) parms.put("kindOrdinary", kindOrdinary + "");

        if (groupkindOrdinary != null) parms.put("groupKindOrdinary", groupkindOrdinary + "");
        if (groupkindGuarantee != null) parms.put("groupKindGuarantee", groupkindGuarantee + "");
        if (groupkindOther != null) parms.put("groupKindOther", groupkindOther + "");
//        if (groupkindOrdinary != null) parms.put("groupKindOrdinary", groupkindOrdinary + "");
//
//        if (groupkindOrdinary != null) parms.put("groupKindOrdinary", groupkindOrdinary + "");
//
//        if (groupkindOrdinary!=null && groupkindOrdinary) {
//            parms.put("kindTax", "1");
//            parms.put("kindOrdinary", "1");
//        }
//        if (groupkindOther!=null && groupkindOther) {
//            parms.put("kindOther", "1");
//        }
//
//        if (groupkindGuarantee!=null && groupkindGuarantee) {
//            parms.put("kindGuarantee", "1");
//        }

        if (minAmountDeclared != null && minAmountDeclared != 0f) parms.put("minAmountDeclared", minAmountDeclared + "");
        if (maxAmountDeclared != null && maxAmountDeclared != 0f) parms.put("maxAmountDeclared", maxAmountDeclared + "");
        if (minConfirmAmount != null && minConfirmAmount != 0f) parms.put("minConfirmAmount", minConfirmAmount + "");
        if (maxConfirmAmount != null && maxConfirmAmount != 0f) parms.put("maxConfirmAmount", maxConfirmAmount + "");
        if (processStatus != null) parms.put("processStatus", processStatus + "");


        showLoading("加载中...");
        Network.getAPIService()
                .getVotesDetail_Manager(parms)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {
                        hideLoading();
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }
                        JsonObject data = json.getAsJsonObject("data");
                        JsonArray arr = data.getAsJsonObject("pageData").getAsJsonArray("list");

                        group.getMemberDetailList().addAll(VoterDetail.parse(arr));
                        group.setCurrentPage(tarPage);
                        group.setTotalPage(data.getAsJsonObject("pageData").get("totalPage").getAsInt());

                        preProcessData();
                        mGroupAdapter.notifyDataSetChanged();
                        if (!group.isReal()) {
                            double amount = data.get("amount").getAsDouble();
                            int totalCount = data.get("memberCount").getAsInt();

                            String str = "";
                            if(mStatus == STATUS_YBJ)
                            {
                                str = "已表决";
                            }
                            if(mStatus == STATUS_YCHWBJ)
                            {
                                str = "已参会未表决";
                            }
                            if(mStatus == STATUS_WCH)
                            {
                                str = "未参会";
                            }

                            if (mStatus == STATUS_YBJ) {
                                tv_voters_overview.setText(str+"人数：" + totalCount + "人    金额合计：" + amount + "元");

                            } else {
                                tv_voters_overview.setText(str+"人数：" + totalCount + "人");
                            }
                        }
                    }

                    @Override
                    public void onCompleted() {
                        hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        hideLoading();
                    }
                });
    }

    private void changeMeeting(VoterDetail info, boolean allow) {
        noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.getId() == R.id.btn_save_notice) {
                    showLoading("加载中...");
                    Network
                            .getAPIService()
                            .changeMeeting_Manager(getUserToken(), info.getId(), info.getVoteId(), allow ? 1 : 0)
                            .subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(new BaseSubscriber<JsonObject>() {
                                @Override
                                public void onNext(JsonObject json) {
                                    hideLoading();
                                    int code = json.get("code").getAsInt();
                                    if (code != 0) {
                                        super.onNext(json);
                                        return;
                                    }
                                    info.setAllowChange(allow);
                                    mGroupAdapter.notifyDataSetChanged();
                                    RefreshEvent event = new RefreshEvent();
                                    event.setType(RefreshEvent.TYPE_VOTER_DETAILS);
                                    EventBus.getDefault().post(event);
                                }

                                @Override
                                public void onCompleted() {
                                    hideLoading();
                                }

                                @Override
                                public void onError(Throwable e) {
                                    hideLoading();
                                }
                            });
                }
                noticeDialog.dismiss();
            }
        }, 1, "提示", "请确认操作已获得有效授权",
                "否", "是");
        noticeDialog.show();

    }

    private PublicNoticeDialog noticeDialog;

    class ProVoteVotersDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

        private final int TYPS_GROUP = 1;
        private final int TYPS_MEMBER = 2;

        private Context mContext;
        private List<Object> mData;


        public ProVoteVotersDetailAdapter(Context context, List<Object> list, LRecyclerView mRecyclerView) {
            mContext = context;
            mData = list;
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int type) {
            if (type == TYPS_GROUP) {
                View v = View.inflate(mContext, R.layout.adapter_pro_vote_voters_detail_group_manager, null);
                // 根据状态显隐
                if (mStatus != STATUS_YBJ) {
                    v.findViewById(R.id.tv_group_overview).setVisibility(View.GONE);
                }
                return new GroupViewHolder(v);
            } else if (type == TYPS_MEMBER) {
                View v = View.inflate(mContext, R.layout.adapter_pro_vote_voters_detail_manager, null);
                // 根据状态显隐


                    if (mStatus == STATUS_YBJ) {
                        v.findViewById(R.id.area_operation_1).setVisibility(View.VISIBLE);
                        v.findViewById(R.id.area_operation_2).setVisibility(View.GONE);
                        v.findViewById(R.id.area_operation_3).setVisibility(View.GONE);
                    } else if (mStatus == STATUS_YCHWBJ) {
                        v.findViewById(R.id.area_operation_1).setVisibility(View.GONE);
                        v.findViewById(R.id.area_operation_2).setVisibility(View.VISIBLE);
                        v.findViewById(R.id.area_operation_3).setVisibility(View.GONE);
                    } else if (mStatus == STATUS_WCH) {
                        v.findViewById(R.id.area_operation_1).setVisibility(View.GONE);
                        v.findViewById(R.id.area_operation_2).setVisibility(View.GONE);
                        v.findViewById(R.id.area_operation_3).setVisibility(View.VISIBLE);
                    }

                    if (mProVoteDetail.getStatus() == ProVote.STATUS_YJS) {
                        v.findViewById(R.id.area_operation_2).setVisibility(View.GONE);
                        v.findViewById(R.id.area_operation_3).setVisibility(View.GONE);
                        v.findViewById(R.id.ck_voter_modify).setVisibility(View.GONE);
                    }
                if(mProVoteDetail.getStatus() !=2 ) {
                    v.findViewById(R.id.area_operation_2).setVisibility(View.GONE);
                    v.findViewById(R.id.area_operation_3).setVisibility(View.GONE);
                    v.findViewById(R.id.ck_voter_modify).setVisibility(View.GONE);
                }

                return new MemberViewHolder(v);
            }
            return null;
        }


        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder0, int position) {

            if (mData.get(position) instanceof VoterGroup) {
                VoterGroup info = (VoterGroup) mData.get(position);
                GroupViewHolder holder = (GroupViewHolder) holder0;


                holder.tv_group_name.setText(info.getName() + "（" + info.getMemberCount() + "）");
                holder.tv_group_overview.setText("表决金额合计：" + CommonUtils.resetMoney(info.getTotalVoteMoney()) + "元");
                if (info.isExpand()) {
                    holder.btn_group_arrow.setImageResource(R.drawable.ic_pro_arrow_up);
                } else {
                    holder.btn_group_arrow.setImageResource(R.drawable.ic_pro_arrow_right);
                }
                holder.btn_group_arrow.setOnClickListener(v -> {
                    // 当前分组未请求过成员数据
                    if (info.getCurrentPage() == 0) {
                        getVotersWithGroupId(info.getId());
                        info.setExpand(true);
                        return;
                    }
                    info.setExpand(!info.isExpand());
                    preProcessData();
                    mGroupAdapter.notifyDataSetChanged();
                });
            } else if (mData.get(position) instanceof VoterDetail) {
                VoterDetail info = (VoterDetail) mData.get(position);
                MemberViewHolder holder = (MemberViewHolder) holder0;
                holder.voter_name.setText(info.getCreditorName());

                Glide.with(getActivity()).load(info.getAvatar())
                        .bitmapTransform(new CropCircleTransformation(getActivity()))
                        .placeholder(R.drawable.logo)
                        .error(R.drawable.logo)
                        .into(holder.voter_avatar);


                if (info.getOnlineStatus() == 2) {
                    holder.tv_online_status.setVisibility(View.VISIBLE);
                } else {
                    holder.tv_online_status.setVisibility(View.GONE);
                }

                if (info.getVoteTime() == 0) {
                    holder.voter_time.setVisibility(View.GONE);
                } else {
                    holder.voter_time.setVisibility(View.VISIBLE);
                    holder.voter_time.setText("表决时间：" + DateFormatUtils.long2Str(info.getVoteTime(), true));
                }
                holder.tv_voter_sure_money.setText("确认金额：" + CommonUtils.resetMoney(info.getConfirmedMoney()) + "元");
                holder.tv_voter_money.setText("表决金额：" + CommonUtils.resetMoney(info.getVoteMoney()) + "元");
                if (!TextUtils.isEmpty(info.getMeetingNumber()) && !TextUtils.equals(info.getMeetingNumber(), "0")) {
                    holder.tv_voter_no.setText("参会编号：" + info.getMeetingNumber());
                    holder.tv_voter_no.setVisibility(View.VISIBLE);
                } else {
                    holder.tv_voter_no.setVisibility(View.GONE);
                }
                if (!TextUtils.isEmpty(info.getSupplementOpinion())) {
                    holder.tv_voter_extra.setText(info.getSupplementOpinion());
                    holder.area_extra_desc.setVisibility(View.VISIBLE);
                } else {
                    holder.area_extra_desc.setVisibility(View.GONE);
                }

                if (info.isCanLoadMore() && info.isLastOne()) {
                    holder.area_load_more.setVisibility(View.VISIBLE);
                    holder.btn_load_more.setOnClickListener(v -> getVotersWithGroupId(info.getGroupId()));
                } else {
                    holder.area_load_more.setVisibility(View.GONE);
                }

                // 不同状态的不同操作
                if (mStatus == STATUS_YBJ) {
                    if (info.getVoteOpinion() == 1) {
                        holder.tv_voter_agree.setText("同意");
                        holder.tv_voter_agree.setBackgroundResource(R.drawable.bg_text_pro_vote_voters_tag_ty);
                        holder.tv_voter_agree.setTextColor(getResources().getColor(R.color.pro_vote_color_agree));


                        holder.tv_voter_agree.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(final View view) {

                                if(mProVoteDetail.getStatus() !=2 )
                                {
                                    return;
                                }
//                                noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
//                                    @Override
//                                    public void onClick(View v) {
//                                        if (v.getId() == R.id.btn_save_notice) {
                                            Intent intent = new Intent(getActivity(),
                                                    ProVoteChangeResultActivity.class);
                                            intent.putExtra(ProVoteChangeResultActivity.KEY_ID, info.getId());
                                            intent.putExtra(ProVoteChangeResultActivity.KEY_NAME,
                                                    info.getCreditorName());
                                            intent.putExtra(ProVoteChangeResultActivity.KEY_ACTION, "new");
                                            startActivity(intent);
//                                        }
//                                        noticeDialog.dismiss();
//                                    }
//                                }, 1, "提示", "请确认操作已获得有效授权",
//                                        "否", "是");
//                                noticeDialog.show();
                            }
                        });


                    } else {
                        holder.tv_voter_agree.setText("不同意");
                        holder.tv_voter_agree.setBackgroundResource(R.drawable.bg_text_pro_vote_voters_tag_bty);
                        holder.tv_voter_agree.setTextColor(getResources().getColor(R.color.pro_vote_color_not_agree));
                        holder.tv_voter_agree.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(final View view) {
                                if(mProVoteDetail.getStatus() !=2 )
                                {
                                    return;
                                }
//                                noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
//                                    @Override
//                                    public void onClick(View v) {
//                                        if (v.getId() == R.id.btn_save_notice) {
                                Intent intent = new Intent(getActivity(),
                                        ProVoteChangeResultActivity.class);
                                intent.putExtra(ProVoteChangeResultActivity.KEY_ID, info.getId());
                                intent.putExtra(ProVoteChangeResultActivity.KEY_NAME,
                                        info.getCreditorName());
                                intent.putExtra(ProVoteChangeResultActivity.KEY_ACTION, "new");
                                startActivity(intent);
//                                        }
//                                        noticeDialog.dismiss();
//                                    }
//                                }, 1, "提示", "请确认操作已获得有效授权",
//                                        "否", "是");
//                                noticeDialog.show();
                            }
                        });
                    }


//                    if (info.isAllowChange()) {
//                        holder.tv_voter_agree.setOnClickListener(v -> {
//                            Intent intent = new Intent(getActivity(), ProVoteChangeResultActivity.class);
//                            intent.putExtra(ProVoteChangeResultActivity.KEY_ID, info.getId());
//                            intent.putExtra(ProVoteChangeResultActivity.KEY_NAME, info.getCreditorName());
//                            startActivity(intent);
//                        });
//                    } else {
//                        holder.tv_voter_agree.setOnClickListener(null);
//                    }
                    holder.ck_voter_modify.setChecked(info.isAllowChange());


                    holder.ck_voter_modify.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(final View view) {

                            boolean allow = ((CheckBox) view).isChecked();

                            String title = "确定要开启修改";
                            String strContent = "开启后债权人可修改已表决结果";
                            if (allow) {
                                title = "确定要开启修改";
                                strContent = "开启后债权人可修改已表决结果";
                            } else {
                                title = "确定要关闭修改";
                                strContent = "关闭后债权人可修改已表决结果";
                            }

                            ((CheckBox) view).setChecked(!allow);
                            noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    if (v.getId() == R.id.btn_save_notice) {
                                        ((CheckBox) view).setChecked(allow);
                                        showLoading("加载中...");
                                        Network
                                                .getAPIService()
                                                .voteAllowChange_Manager(getUserToken(), info.getId(), allow ? 1 : 0)
                                                .subscribeOn(Schedulers.io())
                                                .observeOn(AndroidSchedulers.mainThread())
                                                .subscribe(new BaseSubscriber<JsonObject>() {
                                                    @Override
                                                    public void onNext(JsonObject json) {
                                                        hideLoading();
                                                        int code = json.get("code").getAsInt();
                                                        if (code != 0) {
                                                            super.onNext(json);
                                                            return;
                                                        }
                                                        if (allow) {
                                                            holder.ck_voter_modify.setText("关闭修改");
                                                        } else {

                                                            holder.ck_voter_modify.setText("开启修改");
                                                        }
                                                        info.setAllowChange(allow);
                                                        mGroupAdapter.notifyDataSetChanged();
                                                    }

                                                    @Override
                                                    public void onCompleted() {
                                                        hideLoading();
                                                    }

                                                    @Override
                                                    public void onError(Throwable e) {
                                                        hideLoading();
                                                    }
                                                });
                                    } else {
//                                        ((CheckBox) view).setChecked(!allow);
                                    }

                                    noticeDialog.dismiss();
                                }
                            }, 1, title, strContent,
                                    "取消", "确定");
                            noticeDialog.show();

                        }
                    });


//                    holder.ck_voter_modify.setOnClickListener(v -> allowChange(info, ((CheckBox) v).isChecked()));
                } else if (mStatus == STATUS_YCHWBJ) {
                    holder.btn_meet_cancel.setOnClickListener(v -> changeMeeting(info, false));
                    holder.btn_vote.setOnClickListener(v -> {

//                        noticeDialog = new PublicNoticeDialog(getActivity(), new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                if (v.getId() == R.id.btn_save_notice) {
                        Intent intent = new Intent(getActivity(), ProVoteChangeResultActivity.class);
                        intent.putExtra(ProVoteChangeResultActivity.KEY_ID, info.getId());
                        intent.putExtra(ProVoteChangeResultActivity.KEY_NAME, info.getCreditorName());
                        intent.putExtra(ProVoteChangeResultActivity.KEY_ACTION, "new");
                        startActivity(intent);
//                                }
//                                noticeDialog.dismiss();
//                            }
//                        }, 1, "提示", "请确认操作已获得有效授权",
//                                "否", "是");
//                        noticeDialog.show();

//                        Intent intent = new Intent(getActivity(), ProVoteChangeResultActivity.class);
//                        intent.putExtra(ProVoteChangeResultActivity.KEY_ID, info.getId());
//                        intent.putExtra(ProVoteChangeResultActivity.KEY_NAME, info.getCreditorName());
//                        intent.putExtra(ProVoteChangeResultActivity.KEY_ACTION, "new");
//                        startActivity(intent);
                    });


                } else if (mStatus == STATUS_WCH) {
                    holder.btn_meet.setOnClickListener(v -> changeMeeting(info, true));
                }

                if(mProVoteDetail.getStatus()==4)
                {
                    holder.btn_meet.setVisibility(View.INVISIBLE);
                    holder.btn_vote.setVisibility(View.INVISIBLE);
                    holder.btn_meet_cancel.setVisibility(View.INVISIBLE);
                }
            }



//            VoterDetail info = mData.get(position);
//            holder.voter_name.setText(info.getCreditorName());

        }


        @Override
        public int getItemCount() {
            return mData.size();
        }


        @Override
        public int getItemViewType(int position) {
            if (mData.get(position) instanceof VoterGroup) {
                return TYPS_GROUP;
            } else {
                return TYPS_MEMBER;
            }
        }

        class GroupViewHolder extends RecyclerView.ViewHolder {
            View group;
            TextView tv_group_name;
            TextView tv_group_overview;
            ImageView btn_group_arrow;


            GroupViewHolder(View view) {
                super(view);
                group = view.findViewById(R.id.group);
                tv_group_name = view.findViewById(R.id.tv_group_name);
                tv_group_overview = view.findViewById(R.id.tv_group_overview);
                btn_group_arrow = view.findViewById(R.id.btn_group_arrow);
            }
        }


        class MemberViewHolder extends RecyclerView.ViewHolder {
            TextView voter_name;
            TextView tv_online_status;
            TextView voter_time;
            TextView tv_voter_sure_money;
            TextView tv_voter_money;
            TextView tv_voter_no;
            View area_extra_desc;
            TextView tv_voter_extra;
            ImageView voter_avatar;
            TextView tv_voter_agree;
            CheckBox ck_voter_modify;
            View area_load_more;
            Button btn_load_more;

            View btn_vote, btn_meet, btn_meet_cancel;
            View area_operation_1, area_operation_2, area_operation_3;

            MemberViewHolder(View view) {
                super(view);
                voter_name = view.findViewById(R.id.voter_name);
                voter_avatar = view.findViewById(R.id.voter_avatar);
                tv_online_status = view.findViewById(R.id.tv_online_status);
                voter_time = view.findViewById(R.id.voter_time);
                tv_voter_sure_money = view.findViewById(R.id.tv_voter_sure_money);
                tv_voter_money = view.findViewById(R.id.tv_voter_money);
                tv_voter_no = view.findViewById(R.id.tv_voter_no);
                area_extra_desc = view.findViewById(R.id.area_extra_desc);
                tv_voter_extra = view.findViewById(R.id.tv_voter_extra);
                tv_voter_agree = view.findViewById(R.id.tv_voter_agree);
                ck_voter_modify = view.findViewById(R.id.ck_voter_modify);

                area_load_more = view.findViewById(R.id.area_load_more);
                btn_load_more = view.findViewById(R.id.btn_load_more);

                btn_vote = view.findViewById(R.id.btn_vote);
                btn_meet = view.findViewById(R.id.btn_meet);
                btn_meet_cancel = view.findViewById(R.id.btn_meet_cancel);

                area_operation_1 = view.findViewById(R.id.area_operation_1);
                area_operation_2 = view.findViewById(R.id.area_operation_2);
                area_operation_3 = view.findViewById(R.id.area_operation_3);
            }
        }
    }
}
